package Algorithms.jishi.niuke.huawei.mianshi;

import java.util.ArrayList;
import java.util.List;

/**
 * description: <br>
 * createTime: 2020/12/3 15:33 <br>
 *
 * @author zzh
 */
public class MaxDIfferStringLength {
    public static void main(String[] args) {
        String a = "1A2C3DDD4B56";
        System.out.println(getMaxLength(a));
    }

    public static int getMaxLength(String str) {
        List<String> list = new ArrayList<>();
        char[] chars = str.toCharArray();
        int lastIndex = 0;
        for (int i = 0; i < chars.length - 1; i++) {
            if(chars[i] == chars[i + 1]) {
                list.add(new String(chars, lastIndex, i + 1 - lastIndex));
                lastIndex = i + 1;
            }
        }
        list.add(new String(chars, lastIndex, str.length() - lastIndex));
        int max = 0;
        for (String s : list) {
            if(max < s.length()) {
                max = s.length();
            }
        }
        return max;
    }
}
